using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using csammisrun.shaim;

namespace DefaultUI
{
  /// <summary>
  /// Interaction logic for ListSortingWindow.xaml
  /// </summary>

  partial class ListSortingWindow : Window
  {
    private ICore _core = null;

    public ListSortingWindow(ICore core)
    {
      InitializeComponent();
      _core = core;

      string sorting = _core.LoadSetting("ContactList", "Sorting", "None").ToLower();
      switch (sorting)
      {
        case "alpha":
          AlphaSortOption.IsChecked = true;
          break;
        case "status":
          StatusSortOption.IsChecked = true;
          break;
        default:
          NoSortOption.IsChecked = true;
          break;
      }
      StatusSortOption_CheckedChanged(StatusSortOption, new RoutedEventArgs());
      UseOfflineGroup.IsChecked = _core.LoadSetting("ContactList", "UseOfflineGroup", false);
    }

    void StatusSortOption_CheckedChanged(object sender, RoutedEventArgs e)
    {
      StatusList.IsEnabled = MoveUpButton.IsEnabled = MoveDownButton.IsEnabled = false; // StatusSortOption.IsChecked.Value;
    }

    void StatusList_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
    }

    void OK_Click(object sender, RoutedEventArgs e)
    {
      string value = "None";
      if (NoSortOption.IsChecked.Value)
      {
        value = "None";
      }
      else if (AlphaSortOption.IsChecked.Value)
      {
        value = "Alpha";
      }
      else if (StatusSortOption.IsChecked.Value)
      {
        value = "Status";
      }
      _core.SaveSetting("ContactList", "Sorting", value);
      _core.SaveSetting("ContactList", "UseOfflineGroup", UseOfflineGroup.IsChecked.Value);

      this.DialogResult = true;
    }

    void Cancel_Click(object sender, RoutedEventArgs e)
    {
      this.DialogResult = false;
    }
  }
}